package com.springboot.controller;

import com.alibaba.fastjson.JSON;
import com.springboot.dto.Result;
import com.springboot.facade.UserServiceFacade;
import com.springboot.req.UserReq;
import com.springboot.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "用户注册")
@RestController
@RequestMapping("/user")
public class UserController {

    private static Logger log = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserServiceFacade userServiceFacade;

    @RequestMapping(value = "/register",method = RequestMethod.POST)
    public Result<String> register(@RequestBody UserReq userReq) {
        log.info("register {}", JSON.toJSONString(userReq));
        return userServiceFacade.register(userReq);
    }

    @RequestMapping(value = "/insertUser",method = RequestMethod.POST)
    public Result<String> insertUser() {
        log.info("insertUser start.");
        return userServiceFacade.insertUser();
    }

    @RequestMapping(value = "/login/in",method = RequestMethod.GET)
    public Result<String> loginIn(@ModelAttribute UserReq userReq){
        log.info("loginIn {}", JSON.toJSONString(userReq));
        return userServiceFacade.loginIn(userReq);
    }

    @RequestMapping(value = "/login/out",method = RequestMethod.GET)
    public Result<String> loginOut(@ModelAttribute UserReq userReq){
        log.info("loginOut {}", JSON.toJSONString(userReq));
        return null;
    }

    @RequestMapping(value = "/query",method = RequestMethod.GET)
    public Result<UserVo> query(@ApiParam(value = "银行卡号") String username,HttpServletRequest request){
        log.info("username:{}", JSON.toJSONString(username));
        return userServiceFacade.findByUsername(username);
    }
}